package com.bawei.image

import android.content.Context
import android.widget.ImageView
import com.bawei.image.loader.CoilImgLoader
import com.bawei.image.loader.CustomImgLoader
import com.bawei.image.loader.FrescoImgLoader
import com.bawei.image.loader.GlideImgLoader
import com.bawei.image.loader.PicassoImgLoader
import com.bawei.image.loader.UniversalImgLoader
import java.io.File

/**
 * Author: Jason Zhang
 * Date: 2025/1/13
 * Desc: 统一提供图片加载工具
 */
object LoadImageUtil {

    private var strategy = ImgLoadStrategy.GLIDE
    private var options = ImgOptions.build()
    private var imgLoader: IImgLoader = GlideImgLoader()


    /**
     *  切换图片加载策略
     */
    fun switchStrategy(strategy: ImgLoadStrategy): LoadImageUtil{
        LoadImageUtil.strategy = strategy
        imgLoader = when(strategy){
            ImgLoadStrategy.GLIDE -> GlideImgLoader()
            ImgLoadStrategy.COIL -> CoilImgLoader()
            ImgLoadStrategy.FRESCO -> FrescoImgLoader()
            ImgLoadStrategy.PICASSO -> PicassoImgLoader()
            ImgLoadStrategy.CUSTOM -> CustomImgLoader()
            ImgLoadStrategy.UNIVERSAL -> UniversalImgLoader()

        }
        return this
    }

    fun setOptions(options: ImgOptions): LoadImageUtil{
        this.options = options
        return this
    }

    fun loadImage(ctx: Context, file: File, target: ImageView, opts: ImgOptions = options){
        imgLoader.loadFileIntoImageView(ctx, file, target, opts)
    }

    fun loadUrl(ctx: Context, url: String, target: ImageView, opts: ImgOptions = options){
        imgLoader.loadUrlIntoImageView(ctx, url, target, opts)
    }

    fun loadRes(ctx: Context, resId: Int, target: ImageView, opts: ImgOptions = options){
        imgLoader.loadResIntoImageView(ctx, resId, target, opts)
    }



}